<template>
  <div class="app-container">
    <div class="head-container">
      <el-input v-model="planName" clearable placeholder="输入名称搜索" maxlength="10" style="width: 200px;"
                class="filter-item" @keyup.enter.native="init"/>
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="init">搜索</el-button>
      <el-button
        class="filter-item"
        size="mini"
        type="primary"
        icon="el-icon-plus"
        @click="add">新增
      </el-button>
    </div>
    <el-table v-loading="loading" :data="data" size="small" style="width: 100%;" border>
      <el-table-column
        type="index"
        label="序号"
        align="center"
        width="60">
      </el-table-column>
      <el-table-column prop="trainName" label="培训名称" align="center"/>
      <el-table-column prop="trainDesc" label="培训介绍"  align="center"show-overflow-tooltip/>
      <el-table-column prop="startTime" label="开始时间" width="160" align="center"/>
      <el-table-column prop="endTime" label="结束时间" width="160" align="center"/>
      <el-table-column prop="taskName" label="任务进度"  align="center">
        <template slot-scope="scope">
          <el-progress :percentage="(scope.row.finishCount/scope.row.userCount)*100"></el-progress>
        </template>
      </el-table-column>
      <el-table-column prop="userCount" label="参与人数" width="100" align="center"/>
      <el-table-column prop="finishCount" label="完成人数" width="100" align="center"/>
      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <el-link type="primary" @click="edit(scope.row)" style="font-size: 13px;">编辑</el-link>
          <el-popover
            :ref="scope.row.id"
            placement="top"
            width="180">
            <p>确定删除本条数据吗？</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button>
              <el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.row.id)">确定
              </el-button>
            </div>
            <el-link slot="reference" type="danger" icon="el-icon-delete" size="mini" style="font-size: 13px;">删除</el-link>
          </el-popover>
          <el-link type="primary" @click="toInfo(scope.row)" style="font-size: 13px;">查看详情</el-link>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :total="total"
      :current-page="page + 1"
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"/>
  </div>
</template>

<script>
  import initData from '@/mixins/initData'
  import { del } from '@/api/business/trainPlan'

  export default {
    name: 'index',
    mixins: [initData],
    data() {
      return {
        planName: '',
        planYear: null,
        delLoading: false
      }
    },
    created() {
      this.$nextTick(() => {
        this.init()
      })
    },
    methods: {
      beforeInit() {
        this.url = 'train-plan/page-list'
        this.params = { page: this.page, size: this.size, planName: this.planName, planYear: this.planYear }
        return true
      },
      add() {
        this.$router.push({
          path: '/home/trainAdd'
        })
      },
      edit(row) {
        this.$router.push({
          path: '/home/trainAdd',
          query: { id: row.id }
        })
      },
      subDelete(id) {
        this.delLoading = true
        del(id).then(res => {
          this.$notify({
            title: '删除成功',
            type: 'success',
            duration: 2500
          })
          this.init()
        })
        this.delLoading = false
        this.$refs[id].doClose()
      },
      toInfo(row) {
        this.$router.push({
          path: '/home/trainInfo',
          query: { id: row.id }
        })
      }
    }
  }
</script>

<style scoped>

</style>
